home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / tool / helper / src / helper.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  10.5 KB  |  482 lines

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <string.h>
  4. #include    <ctype.h>
  5. #include    <setjmp.h>
  6. #include    <mos.h>
  7. #include    <fmcfrb.h>
  8. #include    <kkstr2.h>
  9. #include    "scrn.h"
  10. #include    "keyword.h"
  11. #include    "graphic.h"
  12. #include    "dir.h"
  13. #include    "file.h"
  14. #include    "coldef.h"
  15.  
  16. #define    TRUE    1
  17. #define    FALSE    0
  18. #define    ERR    (-1)
  19.  
  20. extern    char    *crent_drive;
  21. extern    char    work[];
  22. extern    int    act_fwc_cdrom;
  23.  
  24.     char    index_file[128];
  25.     int    cur_x=0;
  26.     int    cur_y=0;
  27. static    int    kb_act=0;
  28. static    int     kb_flg=0;
  29. static    int     ch_bak=0;
  30. static    unsigned ec_bak=0;
  31. static    int    kan_col[]={ 15,14,2,13,4,5,6,8,7,9,10,11,12,3,6,0 };
  32. static    jmp_buf    sysreturn;
  33.  
  34. char    *strdup();
  35. int    CTRL_sysdrv();
  36. int    CTRL_command(int code, char *str);
  37. int    PROG_command(char *str);
  38.  
  39. void    GetDspPos(int *x, int *y)
  40. {
  41.     *x = cur_x;
  42.     *y = cur_y;
  43. }
  44. void    Tango_Touroku(char *str)
  45. {
  46.     memcpy(str,0,80);
  47. }
  48. void    INKEY_start(void)
  49. {
  50.     kb_act = 1;
  51.     KYB_clrbuf();
  52.     KAN_disp(KAN_DISPON);
  53. }
  54. void    INKEY_end(void)
  55. {
  56.     kb_act = 0;
  57.     KAN_disp(KAN_DISPOFF);
  58. }
  59. int    kbhit(void)
  60. {
  61.     if ( kb_flg != 0 )
  62.     return 1;
  63.  
  64.     do {
  65.     ch_bak = KYB_read(1,&ec_bak);
  66.     } while ( KAN_inpchk() == KAN_MISET );
  67.  
  68.     if ( (ec_bak & 0xFF00) == 0xFF00 )
  69.     return 0;
  70.  
  71.     kb_flg = 1;
  72.     return 1;
  73. }
  74. int    getch(void)
  75. {
  76.     if ( kbhit() == 0 )
  77.     return EOF;
  78.  
  79.     kb_flg = 0;
  80.     if ( ch_bak  != 0xFFFF ) {
  81.     if ( (ch_bak & 0x8000) != 0 || (ec_bak & 0xFF00) > 0x5100 )
  82.         ch_bak = 0xFFFF;
  83.     switch(ec_bak&0xFF00) {
  84.     case 0x7300: ch_bak = 0x000D; break;
  85.     case 0x7200: ch_bak = 0x001B; break;
  86.     }
  87.     }
  88.     return ((ch_bak & 0xFF00) == 0xFF00 ? EOF:ch_bak);
  89. }
  90. void    KAN_init()
  91. {
  92.     KANJ    kana;
  93.  
  94.     kana.scrn   = KAN_SCRN16;   /*  画面モードは16色モード               */
  95.     kana.egbw   = work;         /*  EGBのワークアドレスを設定する            */
  96.     kana.wPage  = 0;            /*  表示ページを0にする                */
  97.     kana.mosAp  = KAN_MOSON;    /*  マウスの制御をする                 */
  98.     kana.gets   = Tango_Touroku;/*  文字取得ルーチンの設定                 */
  99.     kana.getPos = GetDspPos;    /*  未確定文字列表示位置取得関数の設定 */
  100.     kana.maxX   = 639;          /*  画面の最大X座標                    */
  101.     kana.maxY   = 479;          /*  画面の最大Y座標                    */
  102.  
  103.     KAN_prepare(&kana);
  104.     KAN_setClrTbl(kan_col);
  105. }
  106. int    PRG_clic(int no)
  107. {
  108.     int     i,n,a;
  109.     int     fg;
  110.     char    tmp[256];
  111.  
  112.     if ( prg_tbl[no] == NULL )
  113.     return (no + PRG_NO);
  114.  
  115.     if ( act_fwc_cdrom != prg_tbl[no]->cdrom ) {
  116.     if ( pause("フリコレ%dをセットしてください",
  117.         prg_tbl[no]->cdrom) == ERR )
  118.         return (no + PRG_NO);
  119.     act_fwc_cdrom = prg_tbl[no]->cdrom;
  120.     }
  121.  
  122.     if ( prg_tbl[no]->dir != NULL ) {
  123.     DSP_mos(2);
  124.     if ( prg_tbl[no]->manual == NULL ) {
  125.         if ( (prg_tbl[no]->manual = 
  126.             file_serch(prg_tbl[no]->dir,"*.RRR")) == NULL ) {
  127.             if ( (prg_tbl[no]->manual = 
  128.                 file_serch(prg_tbl[no]->dir,"*.MAN")) == NULL )
  129.             prg_tbl[no]->manual = 
  130.                     file_serch(prg_tbl[no]->dir,"*.DOC");
  131.         }
  132.     }
  133.     if ( prg_tbl[no]->readme == NULL ) {
  134.         if ( (prg_tbl[no]->readme = 
  135.             file_serch(prg_tbl[no]->dir,"*.GGG")) == NULL )
  136.         prg_tbl[no]->readme = 
  137.                 file_serch(prg_tbl[no]->dir,"*.DOC");
  138.     }
  139.     if ( prg_tbl[no]->copycnt == 0 ) {
  140.         if ( (prg_tbl[no]->copy[0] = 
  141.             file_serch(prg_tbl[no]->dir,"*.QQQ")) == NULL ) {
  142.         strcpy(tmp,prg_tbl[no]->dir);
  143.         joint_path(tmp,"*.*");
  144.         prg_tbl[no]->copy[0] = strdup(tmp);
  145.         }
  146.         prg_tbl[no]->copycnt++;
  147.     }
  148.     DSP_mos(0);
  149.     }
  150.  
  151. REDISP:
  152.  
  153.     MSG_disp("%-41.41s",prg_tbl[no]->name);
  154.     MENU_mask(RETN_NO,ON);
  155.     MENU_mask(LIST_NO,OFF);
  156.     MENU_mask(PRNT_NO,OFF);
  157.     MENU_mask(INST_NO,(prg_tbl[no]->copycnt > 0 ? ON:OFF));
  158.     MENU_mask(EXEC_NO,(prg_tbl[no]->exec != NULL ? ON : (-1)));
  159.  
  160.     if ( prg_tbl[no]->readme != NULL ) {
  161.     MENU_mask(LIST_NO,prg_tbl[no]->manual != NULL ? ON:OFF);
  162.     FILE_open(prg_tbl[no]->readme);
  163.     fg = 0;
  164.     } else if ( prg_tbl[no]->manual != NULL ) {
  165.     MENU_mask(TEXT_NO,prg_tbl[no]->readme != NULL ? ON:OFF);
  166.     FILE_open(prg_tbl[no]->manual);
  167.     fg = 1;
  168.     } else {
  169.     FILE_open(NULL);
  170.     fg = (-1);
  171.     }
  172.  
  173.     for ( ; ; ) {
  174.     while ( (i = MENU_no(0)) == NON_NO )
  175.         FILE_irq();
  176.  
  177.     if ( i == CLER_NO )
  178.         break;
  179.     else if ( i == LIST_NO ) {
  180.         if ( fg == 0 && prg_tbl[no]->manual != NULL ) {
  181.         MENU_mask(TEXT_NO,prg_tbl[no]->readme != NULL ? ON:OFF);
  182.         FILE_open(prg_tbl[no]->manual);
  183.         fg = 1;
  184.         } else if ( fg == 1 && prg_tbl[no]->readme != NULL ) {
  185.         MENU_mask(LIST_NO,prg_tbl[no]->manual != NULL ? ON:OFF);
  186.         FILE_open(prg_tbl[no]->readme);
  187.         fg = 0;
  188.         }
  189.     } else if ( i == PRNT_NO )
  190.         FILE_lpt();
  191.     else if ( i == INST_NO )
  192.         COPY_all(prg_tbl[no]->copycnt,prg_tbl[no]->copy);
  193.     else if ( i == BACK_NO )
  194.         FILE_back();
  195.     else if ( i == NEXT_NO )
  196.         FILE_next();
  197.     else if ( i == EXIT_NO ) {
  198.         a = getdrv();
  199.         getdir(tmp);
  200.         if ( prg_tbl[no]->dir[1] == ':' ) {
  201.         if ( !chdrv(toupper(prg_tbl[no]->dir[0])-'A') )
  202.             chdir(prg_tbl[no]->dir);
  203.         } else
  204.         chdir(prg_tbl[no]->dir);
  205.  
  206.         if ( prg_tbl[no]->exec != NULL ) {
  207.         if ( !PROG_command(prg_tbl[no]->exec) )
  208.             JOKE_run(prg_tbl[no]->exec, FALSE);
  209.         } else
  210.         LIST_proc();
  211.  
  212.         if ( !chdrv(a) )
  213.         chdir(tmp);
  214.  
  215. /*********************************
  216.         if ( fg == 0 && prg_tbl[no]->readme != NULL )
  217.         FILE_open(prg_tbl[no]->readme);
  218.         else if ( fg == 1 && prg_tbl[no]->manual != NULL )
  219.         FILE_open(prg_tbl[no]->manual);
  220. **********************************/
  221.         goto REDISP;
  222.     }
  223.     }
  224.  
  225. #ifdef    DEBUG
  226.     MENU_mask(CLER_NO,OFF);
  227.     MENU_mask(LIST_NO,ON);
  228.     MENU_mask(PRNT_NO,ON);
  229.     MENU_mask(INST_NO,ON);
  230.     MENU_mask(EXIT_NO,ON);
  231. #else
  232.     MENU_mask(CLER_NO,OFF);
  233.     MENU_mask(LIST_NO,(-1));
  234.     MENU_mask(PRNT_NO,OFF);
  235.     MENU_mask(INST_NO,OFF);
  236.     MENU_mask(EXIT_NO,ON);
  237. #endif
  238.     MSG_disp("%-41.41s","");
  239.     FILE_close();
  240.     PRG_status();
  241.  
  242.     return i;
  243. }
  244. int    LIST_proc(void)
  245. {
  246.     int     i,n;
  247.     int     fg=0;
  248.     char    *p,*s;
  249.  
  250. LOOP:
  251.     if ( (p = FILE_select()) == NULL )
  252.     return LIST_NO;
  253.  
  254.     if ( JOKE_run(p, TRUE) )
  255.     goto LOOP;
  256.  
  257.     MENU_mask(RETN_NO,ON);
  258.     MENU_mask(LIST_NO,OFF);
  259.     MENU_mask(PRNT_NO,ON);
  260.     MENU_mask(INST_NO,OFF);
  261.     MENU_mask(EXIT_NO,OFF);
  262.     FILE_open(p);
  263.  
  264.     for ( ; ; ) {
  265.     while ( (i = MENU_no(0)) == NON_NO )
  266.         FILE_irq();
  267.  
  268.     if ( i == CLER_NO )
  269.         break;
  270.     else if ( i == PRNT_NO )
  271.         FILE_lpt();
  272.     else if ( i == BACK_NO )
  273.         FILE_back();
  274.     else if ( i == NEXT_NO )
  275.         FILE_next();
  276.  
  277.     }
  278.  
  279. #ifdef    DEBUG
  280.     MENU_mask(CLER_NO,OFF);
  281.     MENU_mask(LIST_NO,ON);
  282.     MENU_mask(PRNT_NO,ON);
  283.     MENU_mask(INST_NO,ON);
  284.     MENU_mask(EXIT_NO,ON);
  285. #else
  286.     MENU_mask(CLER_NO,OFF);
  287.     MENU_mask(LIST_NO,(-1));
  288.     MENU_mask(PRNT_NO,OFF);
  289.     MENU_mask(INST_NO,OFF);
  290.     MENU_mask(EXIT_NO,ON);
  291. #endif
  292.     FILE_close();
  293.     PRG_status();
  294.  
  295.     goto LOOP;
  296. }
  297.  
  298. typedef    struct    _EXE    {
  299.     struct    _EXE    *next;
  300.     char        *wild;
  301.     char        *prog;
  302. } EXEPTR;
  303.  
  304. static    EXEPTR    *prog_top = NULL;
  305.  
  306. void    PROG_append(char *wild, char *prog)
  307. {
  308.     EXEPTR *ep;
  309.  
  310.     if ( (ep = malloc(sizeof(EXEPTR))) == NULL )
  311.     return;
  312.  
  313.     ep->next = prog_top;
  314.     prog_top = ep;
  315.     ep->wild = strdup(wild);
  316.     ep->prog = strdup(prog);
  317. }
  318. int    PROG_command(char *cmds)
  319. {
  320.     int n;
  321.     char *p;
  322.     EXEPTR *ep;
  323.     char tmp[256];
  324.  
  325.     p = cmds;
  326.     while ( isspace(*p) )
  327.     p++;
  328.     for ( n = 0 ; n < 127 && *p != '\0' && !isspace(*p) ; )
  329.     tmp[n++] = *(p++);
  330.     tmp[n] = '\0';
  331.  
  332.     if ( (p = strrchr(tmp, '\\')) != NULL )
  333.     p++;
  334.     else
  335.     p = tmp;
  336.  
  337.     for ( ep = prog_top ; ep != NULL ; ep = ep->next ) {
  338.     if ( wild_mach(ep->wild, p) ) {
  339.         strcpy(tmp, ep->prog);
  340.         strcat(tmp, " ");
  341.         strcat(tmp, cmds);
  342.         if ( !EXEC_input(tmp) && !CTRL_command(1, tmp) )
  343.         longjmp(sysreturn, 1);
  344.         return (-1);
  345.     }
  346.     }
  347.     return 0;
  348. }
  349.  
  350. int    main(int argc,char *argv[])
  351. {
  352.     int     i,n,cdrv;
  353.     char    *p;
  354.     char    *exp;
  355.     char    tmp[4];
  356.  
  357.     cdrv = getdrv();
  358.     tmp[0] = cdrv + 'A'; tmp[1] = ':'; tmp[2] = '\0';
  359.     crent_drive = tmp;
  360.     exp = argv[0];
  361.     index_file[0] = '\0';
  362.  
  363.     if ( argc > 1 ) {
  364.     while ( --argc > 0 ) {
  365.         p = *(++argv);
  366.         if ( *p == '-' || *p == '/' ) {
  367.         switch(toupper(*(p+1))) {
  368.         case 'D':
  369.             p += (*(p+2) == '=' ? 3:2);
  370.             crent_drive = p;
  371.             break;
  372.         }
  373.         } else
  374.         strcpy(index_file,p);
  375.     }
  376.  
  377.     }
  378.  
  379.     if ( index_file[0] == '\0' ) {
  380.     p = exp;
  381.     if ( p[0] != '\0' && p[1] == ':' ) {
  382.         index_file[0] = *(p++);
  383.         index_file[1] = *(p++);
  384.     } else {
  385.         index_file[0] = 'A' + cdrv;
  386.         index_file[1] = ':';
  387.     }
  388.     index_file[2] = '\0';
  389.  
  390.     if ( crent_drive == tmp )
  391.         crent_drive = strdup(index_file);
  392.  
  393.     if ( *p != '\\' ) {
  394.         getdir(index_file+2);
  395.         if ( index_file[3] != '\0' )
  396.         strcat(index_file,"\\");
  397.     }
  398.     strcat(index_file,p);
  399.     if ( (p = strrchr(index_file,'\\')) == NULL )
  400.         for ( p = index_file ; *p != '\0' ; p++ );
  401.     strcpy(p,"\\HELPER.IDX");
  402.     }
  403.  
  404.     DSP_init();
  405.     KAN_init();
  406.  
  407.     DSP_mos(2);
  408.  
  409.     ICON_init();
  410.     SCRN_init();
  411.     DB_init(index_file);
  412.     KEY_cler();
  413.  
  414. #ifdef    DEBUG
  415.     MENU_mask(CLER_NO,OFF);
  416.     MENU_mask(LIST_NO,ON);
  417.     MENU_mask(PRNT_NO,ON);
  418.     MENU_mask(INST_NO,ON);
  419.     MENU_mask(EXIT_NO,ON);
  420. #else
  421.     MENU_mask(CLER_NO,OFF);
  422.     MENU_mask(LIST_NO,(-1));
  423.     MENU_mask(PRNT_NO,OFF);
  424.     MENU_mask(INST_NO,OFF);
  425.     MENU_mask(EXIT_NO,ON);
  426. #endif
  427.  
  428.     DSP_mos(0);
  429.  
  430.     if ( setjmp(sysreturn) != 0 )
  431.     goto ENDOF;
  432.  
  433.     PROG_append("*.EXP", "Q:\\RUN386.EXE");
  434.     PROG_append("*.EXE", "Q:\\ORICON.EXE");
  435.     PROG_append("*.COM", "Q:\\ORICON.EXE");
  436.     PROG_append("*.BAT", "C:\\COMMAND.COM /c");
  437.  
  438.     for ( ; ; ) {
  439.     while ( (i = MENU_no(1)) == NON_NO )
  440.         ;
  441.  
  442.     if ( i == EXIT_NO ) {
  443.         if ( yesno("Are You Sure ?") != (-1) )
  444.             break;
  445.     } else if ( i == CLER_NO )
  446.         KEY_cler();
  447.     else if ( i == LIST_NO )
  448.         LIST_proc();
  449. #ifdef    DEBUG
  450.     else if ( i == PRNT_NO )
  451.         PLT_control();
  452.     else if ( i == INST_NO )
  453.         KEY_input();
  454. #endif
  455.     else if ( i == BACK_NO )
  456.         PRG_back();
  457.     else if ( i == NEXT_NO )
  458.         PRG_next();
  459.     else if ( i == TITL_NO )
  460.         TITL_clic();
  461.     else if ( i == WRIT_NO )
  462.         WRIT_clic();
  463.     else if ( i >= PRG_NO )
  464.         PRG_clic(i - PRG_NO);
  465.     else if ( i >= KEY_NO )
  466.         KEY_clic(i - KEY_NO);
  467.     }
  468.  
  469.     CTRL_command(0x00FF, "");
  470.  
  471. ENDOF:
  472.     KAN_disp(KAN_DISPOFF);
  473.     KAN_finish();
  474.     DSP_end();
  475.  
  476. /********************
  477.     chdrv(cdrv);
  478. *********************/
  479.  
  480.     return 0;
  481. }
  482.